home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / dalib / pvm3 / memcopy.c < prev    next >
C/C++ Source or Header  |  1993-06-15  |  7KB  |  208 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                           *
  4. *  Copyright   : GMD St. Augustin, Germany                                *
  5. *  Date        : Aug 92                                                   *
  6. *  Last Update : Sep 92                                                   *
  7. *                                                                         *
  8. *  This Module is part of the DALIB                                       *
  9. *                                                                         *
  10. *  Module      : memcopy.c                                                *
  11. *                                                                         *
  12. *  Function    : Copying of data in local memory                          *
  13. *                                                                         *
  14. *  Export :                                                               *
  15. *                                                                         *
  16. *      void dalib_memcpy (target, source, size)                           *
  17. *      void dalib_rmemcpy (target, source, size)                          *
  18. *                                                                         *
  19. *      unsigned char *dest, *source;  int size;                           *
  20. *                                                                         *
  21. **************************************************************************/
  22.  
  23. void dalib_memcpy1 (dest, source, size)
  24. unsigned char *dest, *source;
  25. int size;
  26. { int i;
  27.   for (i=0;i<size;i++)
  28.      dest[i] = source[i];
  29. }
  30.  
  31.     /*****************************************************
  32.     *                                                    *
  33.     *    Faster copy if data size is multiple of 4       *
  34.     *                                                    *
  35.     *****************************************************/
  36.  
  37. void dalib_memcpy4 (dest, source, size)
  38. int *dest, *source;
  39. int size;
  40. { int i;
  41.   for (i=0;i<size;i++)
  42.      dest[i] = source[i];
  43. }
  44.  
  45.     /*****************************************************
  46.     *                                                    *
  47.     *    Faster copy if data size is multiple of 8       *
  48.     *                                                    *
  49.     *****************************************************/
  50.  
  51. void dalib_memcpy8 (dest, source, size)
  52. double *dest, *source;
  53. int size;
  54. { int i;
  55.   for (i=0;i<size;i++)
  56.      dest[i] = source[i];
  57. }
  58.  
  59. void dalib_memcpy (target, source, size)
  60. unsigned char *target;
  61. unsigned char *source;
  62. int size;
  63.  
  64. { int hlength;
  65.   int pattern;
  66.  
  67.   pattern = (size | (int) source | (int) target);
  68.  
  69.   if ((pattern & 7) == 0)
  70.      { /* could be double or complex */
  71.        hlength = size / 8;
  72.        dalib_memcpy8 (target, source, hlength);
  73.      }
  74.    else if ((pattern & 3) == 0)
  75.      { /* could be real or int */
  76.        hlength = size / 4;
  77.        dalib_memcpy4 (target, source, hlength);
  78.      }
  79.     else
  80.        dalib_memcpy1 (target, source, size);
  81.  
  82. }
  83.  
  84. void dalib_rmemcpy1 (dest, source, size)
  85. unsigned char *dest, *source;
  86. int size;
  87. { int i;
  88.   for (i=size-1;i>=0;i--)
  89.      dest[i] = source[i];
  90. }
  91.  
  92.     /*****************************************************
  93.     *                                                    *
  94.     *    Faster copy if data size is multiple of 4       *
  95.     *                                                    *
  96.     *****************************************************/
  97.  
  98. void dalib_rmemcpy4 (dest, source, size)
  99. int *dest, *source;
  100. int size;
  101. { int i;
  102.   for (i=size-1;i>=0;i--)
  103.      dest[i] = source[i];
  104. }
  105.  
  106.     /*****************************************************
  107.     *                                                    *
  108.     *    Faster copy if data size is multiple of 8       *
  109.     *                                                    *
  110.     *****************************************************/
  111.  
  112. void dalib_rmemcpy8 (dest, source, size)
  113. double *dest, *source;
  114. int size;
  115. { int i;
  116.   for (i=size-1;i>=0;i--)
  117.      dest[i] = source[i];
  118. }
  119.  
  120.     /*****************************************************
  121.     *                                                    *
  122.     *    Reverse memory copy: must be called if          *
  123.     *                                                    *
  124.     *       source < target <= source+size               *
  125.     *                                                    *
  126.     *            --------------------------------        *
  127.     *            |   target data                |        *
  128.     *            --------------------------------        *
  129.     *        --------------------------------            *
  130.     *        |   source data                |            *
  131.     *        --------------------------------            *
  132.     *                                                    *
  133.     *    for (i=0;i<size;i++) target[i] = source[i]      *
  134.     *      would destroy source data !!!                 *
  135.     *                                                    *
  136.     *****************************************************/
  137.  
  138. void dalib_rmemcpy (target, source, size)
  139. unsigned char *target;
  140. unsigned char *source;
  141. int size;
  142.  
  143. { int hlength;
  144.   int pattern;
  145.  
  146.   pattern = (size | (int) source | (int) target);
  147.  
  148.   if ((pattern & 7) == 0)
  149.      { /* could be double or complex */
  150.        hlength = size / 8;
  151.        dalib_rmemcpy8 (target, source, hlength);
  152.      }
  153.    else if ((pattern & 3) == 0)
  154.      { /* could be real or int */
  155.        hlength = size / 4;
  156.        dalib_rmemcpy4 (target, source, hlength);
  157.      }
  158.     else
  159.        dalib_rmemcpy1 (target, source, size);
  160.  
  161. }
  162.  
  163.     /*****************************************************
  164.     *                                                    *
  165.     *    Indirect addressing of local memory for         *
  166.     *    different data sizes (1, 4, 8)                  *
  167.     *                                                    *
  168.     *****************************************************/
  169.  
  170. void dalib_memget4 (target, source, index, n)
  171. int *target, *source;
  172. int *index, n;
  173.  
  174. { int i;
  175.   for (i=0; i<n; i++)
  176.      target[i] = source[index[i]];
  177. }
  178.  
  179. void dalib_memgetm4 (target, source, index, n)
  180. int *target, *source;
  181. int *index, n;
  182.  
  183. { int i;
  184.   for (i=0; i<n; i++)
  185.    if (index[i] >= 0)
  186.      target[i] = source[index[i]];
  187. }
  188.  
  189. void dalib_memget8 (target, source, index, n)
  190. double *target, *source;
  191. int *index, n;
  192.  
  193. { int i;
  194.   for (i=0; i<n; i++)
  195.      target[i] = source[index[i]];
  196. }
  197.  
  198. void dalib_memgetm8 (target, source, index, n)
  199. double *target, *source;
  200. int *index, n;
  201.  
  202. { int i;
  203.   for (i=0; i<n; i++)
  204.    if (index[i] >= 0)
  205.      target[i] = source[index[i]];
  206. }
  207.  
  208.